package com.kobe.game_60;

import java.util.Arrays;

import com.kobe.util.MathUtil;

/**
 * 
 * We shall say that an n-digit number is pandigital if it makes use of all the
 * digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is
 * also prime.
 * 
 * What is the largest n-digit pandigital prime that exists?
 *
 * 
 */
public class _41 {

    public static boolean isPandigital(int number) {
        char[] numberArray = String.valueOf(number).toCharArray();
        Arrays.sort(numberArray);
        for (int i = 0; i < numberArray.length; i++) {
            if (Character.getNumericValue(numberArray[i]) != i + 1) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {

        for (int i = 3; i < 987654321; i = i + 2) {
            if (MathUtil.isPrime(i)) {
                if (isPandigital(i)) {
                    System.out.println(i);
                }
            }
        }

    }
}
